<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.dao.${className}Dao">
    <resultMap id="BaseResultMap" type="${packageName}.entity.${className}">
    <#list xml as a>
        <#if a_index==0>
        <id column="${a.field}" property="${a.fields}"/>
        <#else>
        <result column="${a.field}" property="${a.fields}"/>
        </#if>
    </#list>
    </resultMap>

    <sql id="Base_Column_List">
    <#list xml as a>
        ${a.field}<#if a_has_next>,</#if>
    </#list>
    </sql>

    <select id="get" resultMap="BaseResultMap" parameterType="${packageName}.entity.${className}">
        select
        <include refid="Base_Column_List"/>
        from ${table}
        <where>
            del_flag = '0'
            <#list xml as a>
                <#if a_index ==0>
          <if test="${a.fields} != null and ''!=${a.fields}">
              and ${a.field} = #${m}${a.fields}${n}
          </if>
                </#if>
                <#if (a_index >0)>
                    <#if a.filterOut>
           <if test="${a.fields} != null and ''!=${a.fields}">
               and ${a.field} = #${m}${a.fields}${n}
           </if>
                    </#if>
                </#if>
            </#list>
        </where>
    </select>

    <select id="findList" resultMap="BaseResultMap" parameterType="${packageName}.entity.${className}">
        select
        <include refid="Base_Column_List"/>
        from ${table}
        <where>
            del_flag = '0'
            <#list xml as a>
                <#if a_index ==0>
           <if test="${a.fields} != null and ''!=${a.fields}">
               and ${a.field} = #${m}${a.fields}${n}
           </if>
                </#if>
                <#if (a_index >0)>
                    <#if a.filterOut>
           <if test="${a.fields} != null and ''!=${a.fields}">
               and ${a.field} = #${m}${a.fields}${n}
           </if>
                    </#if>
                </#if>
            </#list>
        </where>
        order by create_date desc
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="${packageName}.entity.${className}">
        insert into ${table}(
        <include refid="Base_Column_List"/>
        ) values (
        <#list xml as a>
            #${m}${a.fields}${n}<#if a_has_next>,</#if>
        </#list>
        )
    </insert>

    <update id="update" parameterType="${packageName}.entity.${className}">
        update ${table} set
        <#list xml as a>
            ${a.field}=#${m}${a.fields}${n}<#if a_has_next>,</#if>
        </#list>
        where id =  <#list xml as a> <#if a_index ==0>#${m}${a.field}${n}</#if> </#list>
    </update>

    <update id="logicalDeletion" parameterType="java.lang.<#list xml as a><#if a_index ==0>${a.types}</#if></#list>">
        update ${table} set del_flag = '1' where id = <#list xml as a> <#if a_index ==0>
        #${m}${a.field}${n}</#if> </#list>
    </update>

    <delete id="actualDeletion" parameterType="${packageName}.entity.${className}">
        delete from ${table} where id = <#list xml as a> <#if a_index ==0>#${m}${a.field}${n}</#if> </#list>
    </delete>


    <update id="delete" parameterType="java.util.List">
        update ${table} set del_flag ='1' where id in(
        <foreach collection="ids" item="id" separator=",">
            #${m}id${n}
        </foreach>
        )
    </update>

</mapper>